package com.sky.controller.admin;

import com.sky.context.BaseContext;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.dto.PasswordEditDTO;
import com.sky.entity.Employee;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
public class EmpController {

@Autowired
    private EmpService empService;
@PutMapping("/employee/editPassword")
    public Result<String> upDate(@RequestBody PasswordEditDTO passwordEditDTO){
    passwordEditDTO.setEmpId(BaseContext.getCurrentId());
    empService.upDate(passwordEditDTO);
    return Result.success();
}
@PostMapping ("/employee/status/{status}")
    public Result<String> status(@PathVariable Integer status ,Long id){
    empService.status(status,id);
    return  Result.success();
}
@GetMapping("/employee/page")
    public Result<PageResult> findPage(EmployeePageQueryDTO employeePageQueryDTO){
      PageResult pageResult =  empService.findAll(employeePageQueryDTO.getPage(),employeePageQueryDTO.getPageSize(),employeePageQueryDTO.getName());
      return Result.success(pageResult);
}

@PostMapping("/employee")
    public Result<String> add(@RequestBody EmployeeDTO employeeDTO){
    empService.add(employeeDTO);
    return Result.success();
}
@GetMapping("/employee/{id}")
    public Result<Employee> findById(@PathVariable Long id){
   Employee employee =  empService.findById(id);
    return Result.success(employee);
}
@PutMapping("/employee")
    public Result<String> upDateEmp(@RequestBody EmployeeDTO employeeDTO){
       empService.upDateEmp(employeeDTO);
       return Result.success();
}

}